package git.soulbgm.config;

import git.soulbgm.common.base.BaseDataSourceConfig;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import tk.mybatis.spring.annotation.MapperScan;

import javax.sql.DataSource;

/**
 * 主数据源
 *
 * @author SoulBGM
 * @version 1.0
 * @date 2019/11/25 10:15
 */
@Configuration
@MapperScan(basePackages = "git.soulbgm.mapper.primary", sqlSessionTemplateRef = "primarySqlSessionTemplate")
public class PrimaryDataSourceConfig extends BaseDataSourceConfig {

    @Bean("primaryDataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.primary")
    @Override
    public DataSource dataSource() {
        return super.dataSource();
    }

    @Bean("primarySqlSessionFactory")
    @Primary
    @Override
    public SqlSessionFactory sqlSessionFactory() {
        return super.sqlSessionFactory();
    }

    @Bean("primaryTransactionManager")
    @Primary
    @Override
    public DataSourceTransactionManager transactionManager() {
        return super.transactionManager();
    }

    @Bean("primarySqlSessionTemplate")
    @Primary
    @Override
    public SqlSessionTemplate sqlSessionTemplate() {
        return super.sqlSessionTemplate();
    }

}
